<template>
  <div class="app-container">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input size="small" v-model="queryItems[0].value" placeholder="名称" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button  icon="el-icon-plus" size="mini" type="primary"   @click="addOrUpdateHandle()">添加</el-button>
      </el-form-item>
      <el-form-item>
        <el-button   type="danger" icon="el-icon-delete" size="mini"  @click="deleteHandle()">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      size="mini"
      v-loading="dataListLoading"
      :data="dataList"
      border
      stripe
      @selection-change="dataListSelectionChangeHandle"
      @sort-change="dataListSortChangeHandle"
      style="width: 100%;">
      <el-table-column type="selection" header-align="center" align="center" width="50"/>
      <el-table-column prop="name" label="名称" header-align="center" align="center"/>
<!--      <el-table-column prop="url" :label="$t('banner.url')" header-align="center" align="center">-->
<!--        <template slot-scope="scope">{{ imageUrlRoot+scope.row.url }}</template>-->
<!--      </el-table-column>-->
      <el-table-column
              label="预览"
              width="150"
              align="center">
        <template slot-scope="scope">
          <el-image
                  fit="cover"
                  style="width: 120px; height: 80px"
                  :src="imageUrlRoot+scope.row.url"
                  :preview-src-list="[imageUrlRoot+scope.row.url]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column prop="sort" label="排序" header-align="center" align="center"/>
      <el-table-column prop="status" label="状态" sortable="custom" header-align="center" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" size="mini" type="danger">禁用</el-tag>
          <el-tag v-else size="mini" type="success">启用</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" header-align="center" align="center"/>
      <el-table-column prop="createTime" label="创建时间" sortable="custom" header-align="center" align="center" width="180"/>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template slot-scope="scope">
          <el-button  type="text" size="mini" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button   type="text" size="mini" @click="enableHandle(scope.row)">{{ scope.row.status === 0?'启用':'禁用'}}</el-button>
          <el-button  type="text" size="mini" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"/>
    <!-- 分页 -->
    <el-pagination
      slot="footer"
      :current-page="page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="limit"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="pageSizeChangeHandle"
      @current-change="pageCurrentChangeHandle">
    </el-pagination>
  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './banner-add-or-update'
export default {
  mixins: [ mixinViewModule ],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/manager/banner/page',
        getDataListIsPage: true,
        deleteURL: '/manager/banner/delete',
        deleteIsBatch: true,
        enableURL: '/manager/banner/enableBanner'
      },
      imageUrlRoot: process.env.VUE_APP_IMG,
      dataForm: {

      },
      queryItems: [
        {
          field: 'name',
          as: 'LIKE',
          value: ''
        }
      ],
      order: 'ASC',
      orderField: 'sort'
    }
  },
  components: {
    AddOrUpdate
  },
  methods:{
    // enableHandle(row){
    //   let dataItem = Object.assign({}, row) //拷贝数据对象
    //   dataItem.status = status === 1 ? 0 : 1
    //   let params =  {
    //     id:dataItem.id,
    //     type: dataItem.type,
    //     status:dataItem.status
    //   };
    //   this.$http.post('/banner/enableBanner', params).then(res => {
    //     this.$message({
    //       message: this.$t('prompt.success'),
    //       type: 'success',
    //       duration: 500,
    //       onClose: () => {
    //         this.visible = false
    //         this.$emit('refreshDataList')
    //       }
    //     })
    //   }).catch(() => {})
    // }

  }
}
</script>
